package com.itheima.test7;

public class girlFriendTest {
    public static void main(String[] args) {
        //要求计算平均年龄
        //统计年龄比平均值低的有多少个，并打印所有信息
        //定义数组存入女朋友对象
        girlFriend[] gf = new girlFriend[4];

        //创建女朋友对象
        girlFriend gf1 = new girlFriend("小红", 18, "女", "看电影");
        girlFriend gf2 = new girlFriend("小明", 20, "男", "打游戏");
        girlFriend gf3 = new girlFriend("小绿", 19, "女", "看小说");
        girlFriend gf4 = new girlFriend("小蓝", 21, "男", "看电影");

        //将女朋友对象存入数组
        gf[0] = gf1;
        gf[1] = gf2;
        gf[2] = gf3;
        gf[3] = gf4;

        //求和
        int sum = 0;
        for (int i = 0; i < gf.length; i++) {
            sum += gf[i].getAge();
        }

        int avg = sum / gf.length;
        System.out.println("平均年龄为：" + avg);

        //统计年龄比平均值低的有多少个，并打印所有信息
        int count = 0;
        for (int i = 0; i < gf.length; i++) {
            if(gf[i].getAge() < avg){
                count++;
                System.out.println(gf[i].getName() + " " + gf[i].getAge() + " " + gf[i].getGender() + " " + gf[i].getHobby());
            }
        }
        System.out.println("平均年龄以下的有" + count);
    }
}
